package ru.autofan.support;

import org.springframework.context.ApplicationContext;
import org.springframework.util.StringUtils;

public class BeanAccessor {

	ApplicationContext applicationContext;
	
	public BeanAccessor(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getBean(Class<T> clazz) {
		String className = clazz.getSimpleName();
		className = StringUtils.uncapitalize(className);
		return (T) applicationContext.getBean(className);
	}
}
